Skip to content

Add a new color group for selections within highlighted search results - #3827

Open
masmu wants to merge 1 commit into
micro-editor:masterfrom
masmu:feature/hlsearch-selection-colorscheme-group
Open

masmu wants to merge 1 commit into
micro-editor:masterfrom
masmu:feature/hlsearch-selection-colorscheme-group

Conversation

@masmu

@masmu masmu commented Aug 7, 2025 •

Copy link
Copy Markdown
Contributor

micro allows to set the color for selections and for search results. However, if your color scheme defines a color for selections that is very similar to your general background color, and you perform a search, the currently selected text will hardly stand out.

hlsearch-selection The red arrow indicates the currently selected text.

Since this cannot be done with plugins, it would be great if we can add a new color-group analogous to statusline, statusline.inactive, statusline.suggestions.

@masmu
masmu force-pushed the feature/hlsearch-selection-colorscheme-group branch from bd654df to 8973a3c Compare November 6, 2026 12:45
@dmaluka

dmaluka commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

However, if your color scheme defines a color for selections that is very similar to your general background color, and you perform a search, the currently selected text will hardly stand out.

I'm a bit confused. If it hardly stands out, it hardly stands out regardless of whether you perform a search or not?

And generally such a problem is just a problem of a particular colorscheme, right? (And BTW can be easily worked around by the user, by copying the colorscheme to the user's ~/.config/micro/colorschemes and adjusting the needed colors?)

@masmu

masmu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

And generally such a problem is just a problem of a particular colorscheme, right?

Well, yes and no. I am trying to mimic the colorscheme I am using in all of my editors. Therefore I am using my own custom user colorscheme in ~/.config/micro/colorschemes.
And every color in every colorscheme (for all the editors) is pretty much hand picked.
So I guess you can say that making them almost indistinguishable from each other is quite a big deal for me.

But I understand the confusion, let me explain this in more detail.

The following image shows how I would like selections to look like (because thats how it looks in my other editors).

micro-pure-selection

The next image shows how I would like search results to look like (for the same reason I mentioned earlier).

micro-pure-search

There are already color groups for these cases, and I've set the colors the way I'm used to. So everything's fine so far.
However, when you actually select a search result, it's hardly noticeable. That state is illustrated by the first image in the PR.
So, when you say, thats not a great colorscheme because you are running into those problems, then yes, thats the problem of my particular colorscheme.

Thats why I would like to introduce a new color group, which makes that distinguishable, like in the following image.

micro-search-and-selection-combined

To be honest, I realize that this is probably mainly for my own benefit, but I hope others can benefit from it as well. Since there are already sub-color-groups in the code (for example, statusline has the sub-color-groups statusline.inactive and statusline.suggestions), I thought I'd just give it a try and hope for the best.

@dmaluka

dmaluka commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Do those other editors you are using also have an equivalent of your hlsearch.selection?

This just seems quite odd to me in terms of user experience: the selection color suddenly changes (e.g. from dark gray to yellow in your example) just because we've searched some text so it got highlighted.

EDIT: I take it back, I've just tried your PR and I see it does a different thing than what I thought: the hlsearch.selection color is only applied to a selection (or a part of it) than is within a hlsearch'ed text, not to any selection.

This actually seems quite reasonable to me, and might be useful even regardless of color contrast issues.

@masmu

masmu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

This actually seems quite reasonable to me, and might be useful even regardless of color contrast issues.

I am glad you like it. Made my day.

This might be a little off-topic, but I read that question between the lines.

You were absolutely right that a standard selection within my color scheme hardly stands out anyway.
But there's a good reason for that. I also use a patch that preserves the foreground color of the selected text (the colors are already there, we're just overwriting them). And this works significantly better when the selection does not completely draw the user's attention (by means of a bold color).
Otherwise, the foreground colors of the text will blend too much into the background color of the selection.

colored-selections

Comment thread internal/display/bufwindow.go Outdated

if highlight {
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
isHighlightSearchMatch := w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just highlightSearchMatch. This boolean is not a characteristic of something (like isActive, isModified, isEol and so on), it is an indication whether to do something. IOW, "is highlight search match" ("is" followed by a verb in the imperative mood) is not grammatically correct, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The is + verb combination is ungrammatical.

Renamed to highlightSearchMatch.

@masmu
masmu force-pushed the feature/hlsearch-selection-colorscheme-group branch from 8973a3c to 055dab4 Compare November 18, 2026 08:47
Comment thread runtime/help/colors.md Outdated
* error-message (Color of error messages in the bottom line of the screen)
* match-brace (Color of matching brackets when `matchbracestyle` is set to `highlight`)
* hlsearch (Color of highlighted search results when `hlsearch` is enabled)
* hlsearch.selection (Color of the selection within highlighted search results when `hlsearch` is enabled)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this line at ~80 characters, in line with the rest of this help doc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. 👍

micro allows setting colors for selections and for search
results. If a colorscheme defines a selection color that is
very similar to the hlsearch highlight color, the currently
selected text will hardly stand out during a highlighted
search.

So add a new color-group analogous to `statusline`,
`statusline.inactive`, `statusline.suggestions`.
@masmu
masmu force-pushed the feature/hlsearch-selection-colorscheme-group branch from 055dab4 to 4ea2eb2 Compare November 18, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants